package com.bwf.http;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/6/8 11:19
 * @Copyright 博为峰
 */
public class ServletDemo02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        System.out.println("doGet name = " + name);
        //响应数据之前
        resp.setContentType("text/html;charset=utf8");
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("<h1>成功</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决请求乱码
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        System.out.println("doPost name = " + name);
        //响应数据之前
        resp.setContentType("text/html;charset=utf8");
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("<h1>成功</h1>");
    }
}
